import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Test6 {
	public static void main(String[] args) {
		/*
		 * 读文本文件
		 */
		BufferedReader br=null;
		BufferedWriter bw=null;
		try {
			br = new BufferedReader(new FileReader("Pet.template"));
			bw = new BufferedWriter(new FileWriter("Pet.txt"));
			StringBuffer buffer = new StringBuffer();
			//声明变量，存储一行字符串
			String line=null;
			while((line=br.readLine())!=null) {
				buffer.append(line);
			}
			String content = buffer.toString().replace("{name}", "多多").replace("{type}", "狗狗").replace("{master}", "李伟");;
			bw.write(content);
			bw.flush();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				bw.close();
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
